<%-- 
    Document   : register
    Created on : 02 2, 12, 6:07:54 PM
    Author     : pauld
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <%
        String user = (String)session.getAttribute("user");
        String name = (String)session.getAttribute("name");
        
        //if user is already logged in
        if(user != null) {
            response.sendRedirect("main.jsp");
        }
        %>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        
        <link rel="stylesheet" href="css/960_24_col.css" />
        <link rel="stylesheet" href="css/reset.css" />
        <link rel="stylesheet" href="css/text.css" />
        <link rel="stylesheet" href="css/style.css" />
        
        <script type="text/javascript" src="scripts/jquery.js"></script>
        <script type="text/javascript" src="scripts/formScripts.js"></script>
        
        <title>FooBar Online Bookstore | Register</title>
    </head>
    <body>
        <div id="bar"></div>
        <!-------------------------------header here----------------------->
            <div id="header-wrap">
                <div id="dashboard" class="container_24">
                    <div id="dashboard-logo" class="grid_7">
                        <a href="index.jsp"><img src="images/logo.png" alt="logo" /></a>
                    </div>
                    <div id="dashboard-menu" class="grid_17">
                        <ul class="menu" id="main-menu">
                            <li><a href="index.jsp">Home</a></li>
                            <li><a href="main.jsp">Products</a>
                                <ul style="display: none">
                                    <li><a href="main.jsp?show=book">Books</a></li>
                                    <li><a href="main.jsp?show=mags">Magazines</a></li>
                                    <li><a href="main.jsp?show=cd">CD</a></li>
                                    <li><a href="main.jsp?show=dvd">DVD</a></li>
                                    <li><a href="main.jsp?show=acc">Accessories</a></li>
                                </ul>
                            </li>
                            <li><a href="about.jsp">About</a></li>
                            <li><a href="contact.jsp">Contact Us</a></li>
                            <%
                            if(user == null){
                                out.println("<li><a href='login.jsp'>Login</a> | <a href='register.jsp'>Join Now</a></li>");
                            }
                            else{
                                out.println("<li><form action='logout' name='logout' method='post'>"
                                + "<a id='user-header' href='myProfile.jsp'>" + name + "</a>"
                                + "<input type='submit' value='Logout' class='submit-button' />"
                                + "</form></li>");
                            }
                            %>
                        </ul>
                    </div>
                </div>
            </div>
        <!-------------------------------content here----------------------->
        <div id="content-wrap">
            <div id="content" class="container_24">
                <div class="grid_12">
                    <h1>Register Here!</h1>
                
                <!--Form for registering new users-->
                    <form action="register" method="post" id="register-form" class="styled-form">
                        <label>*Username: </label><br />
                        <input type="text" id="register-uname" name="register-uname" class="form-inputs" maxlength="25"
                               value="<% if( session.getAttribute("reg-uname") != null )out.println(session.getAttribute("reg-uname")); %>"/><br />
                        
                        <label>*Password: </label><br />
                        <input type="password" id="register-pw1" name="register-pw1" class="form-inputs" maxlength="25" /><br />
                        
                        <label>*Confirm Password: </label><br />
                        <input type="password" id="register-pw2" name="register-pw2" class="form-inputs" maxlength="25" /><br />
                        
                        <label>*E-mail: </label><br />
                        <input type="text" id="register-email" name="register-email" class="form-inputs" maxlength="25" 
                               value="<% if( session.getAttribute("reg-email") != null )out.println(session.getAttribute("reg-email")); %>"/><br />
                        
                        <label>Last Name: </label><br />
                        <input type="text" id="register-lname" name="register-last_name" class="form-inputs" maxlength="25"
                               value="<% if( session.getAttribute("reg-lname") != null )out.println(session.getAttribute("reg-lname")); %>"/><br />
                        
                        <label>First Name: </label><br />
                        <input type="text" id="register-fname" name="register-first_name" class="form-inputs" maxlength="25"
                               value="<% if( session.getAttribute("reg-fname") != null )out.println(session.getAttribute("reg-fname")); %>"/><br />
                        
                        <label>Middle Initial: </label><br />
                        <input type="text" id="register-minitial" name="register-middle_initial" class="form-inputs" maxlength="1"
                               value="<% if( session.getAttribute("reg-mname") != null )out.println(session.getAttribute("reg-mname")); %>"/><br />
                        
                        <label>*Address: </label><br />
                        <textarea id="register-add" class="form-inputs" name="register-add" cols="30" rows="10" maxlength="45"><% if( session.getAttribute("reg-add") != null )out.println(session.getAttribute("reg-add")); %></textarea><br />
                        
                        <label>*Country: </label><br />
                        <select name="register-country" id="register-country">
                            <option value=""></option>
                            <option value="Philippines">Philippines</option>
                        </select><br />
                        
                        <label>*Zip: </label><br />
                        <input type="text" id="register-zip" name="register-zip" class="form-inputs" maxlength="4"
                               value="<% if( session.getAttribute("reg-zip") != null )out.println(session.getAttribute("reg-zip")); %>"/><br />
                        
                        <input type="submit" value="Submit" class="submit-button"/>
                    </form>
                </div>
                <div class="grid_12" >
                    <ul class="error-pane" id="register-error_pane">
                        <%
                        //this shows the errors when you resgister
                        try{
                            if( request.getParameter("status").equals("2") ){
                                out.println("<li class='important'>Your Username has Already Been taken</li>");
                            }
                            else if( request.getParameter("status").equals("0") ){
                                out.println("<li class='important'>Please Fill Up The Form Correctly</li>");
                            }
                            else if( request.getParameter("status").equals("-1") ){
                                out.println("<li class='important'>Ooops Something Went Wrong Please Try Again Later</li>");
                            }
                        }
                        catch(NullPointerException e1){

                        }
                        catch(Exception e1){

                        }
                        %>
                        <li style="display: none;" id='register-error-uname'>Username should be 4 to 25 characters long</li>
                        <li style="display: none;" id='register-error-pw'>Password should be 8 to 25 characters long</li>
                        <li style="display: none;" id='register-error-pw-same'>Password should match</li>
                        <li style="display: none;" id='register-error-email'>Please enter a valid e-mail address</li>
                        <li style="display: none;" id='register-error-name'>Your name is too long</li>
                        <li style="display: none;" id='register-error-add'>Please enter your address</li>
                        <li style="display: none;" id='register-error-country'>Please select a country</li>
                        <li style="display: none;" id='register-error-zip'>Please enter a valid zip code</li>
                    </ul>
                </div>
            </div>
        </div>
        <!-------------------------------footer here----------------------->
        <div id="upper-footer-wrap">
            <div id="upper-footer" class="container_24">
                <div class="grid_7 prefix_17">
                    <ul class="menu">
                        <li><a href="#">top</a></li>
                        <li><a href="index.jsp">home</a></li>
                        <li><a href="contact.jsp">contact us</a></li>
                    </ul>
                </div>
            </div>
        </div>
        <div id="lower-footer-wrap">
            <div id="lower-footer" class="container_24">
                <center>
                    <p>FooBar Online Bookstore SECPROG Project</p>
                </center>
            </div>
        </div>
    </body>
</html>
